<template>
  <div class="icons">
    <swiper :options="swiperOption">
      <swiper-slide v-for="(page, index) of pages" :key="index">
        <div
          class="icon"
          v-for="item of page"
          :key="item.id"
        >
          <div class="icon-content">
            <img class="icon-img" :src="item.imgUrl" />
          </div>
          <p class="icon-img-content">{{item.desc}}</p>
        </div>
      </swiper-slide>
      <div class="swiper-pagination" slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        autoplay: false
      }
    }
  },
  computed: {
    pages () {
      let pages = []
      this.list.forEach((item, index) => {
        let page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="stylus" scoped>
  @import '~styles/variable.styl'
  @import '~styles/mixins.styl'
  .icons >>> .swiper-container
    width: 100%
    height: 0
    padding-bottom: 50%
  .icons >>> .swiper-pagination-bullet
    width: 7px
    height: 7px
  .icon
    overflow: hidden
    position: relative
    float: left
    height: 0
    width: 25%
    padding-bottom: 23%
    .icon-content
      position: absolute
      left: 0
      right: 0
      top: 0
      bottom: .44rem
      box-sizing: border-box
      padding: .1rem
      .icon-img
        display: block
        margin: .05rem auto
        height: 100%
    .icon-img-content
      height: .44rem
      line-height: .44rem
      text-align: center
      position: absolute
      left: 0
      right: 0
      bottom: 0
      color: $darkTextColor
      ellipsis()
  .swiper-pagination
    position: absolute
    bottom: 0
    margin-left: -.06rem
</style>
